// JavaScript Document
var timer = null;
var offset = 3000;
var index = 3;
var left = 0;
var target = ["01","02","03","04"];

//大图交替轮换
function slideImage(i){
    var id = 'pic_'+ target[i];
    $('#'+ id)
        .animate({opacity: 1}, 800, function(){
        }).show()
        .siblings(':visible')
		.animate({opacity: 1}, 800).hide();
}
//bind smallpic a
function hookThumb(){    
    $('#num li a')
        .bind('mousemove', function(){
            if (timer) {
                clearTimeout(timer);
            }                
            var id = this.id;            
            index = getIndex(id.substr(4));
            rechange(index);
            slideImage(index); 
            timer = window.setTimeout(auto, offset);  
            this.blur();            
            return false;
        });
}

//get index
function getIndex(v){
    for(var i=0; i < target.length; i++){
        if (target[i] == v) return i;
    }
}

function rechange(loop){
    var nid = 'num_'+target[loop];
	var cid = 'cnt_'+target[loop];
	$('#num li a').removeClass('anniu_cur');
	$('#'+nid).addClass('anniu_cur');
	$('#cnt li').addClass('hidden');
	$('#'+cid).removeClass();
}

function auto(){
    index++;
    if (index > 3){
        index = 0;
    }
    rechange(index);
    slideImage(index);
    timer = window.setTimeout(auto, offset);
}

$(function(){    
    auto();  
    hookThumb(); 
    hookBtn();   
});